# # 相除
# def div(a, b):
#     return a/b
#
# f = open("data.txt")
# try:
#     print(div(1, 1))
#     list1 = [1,2,3]
#     print(list1[2])
#     f.readline()
#
# except Exception as e:
#     print(e)
#     print("这里有个异常")
# else:
#     print("没有异常的时候执行")
# finally:
#     # finally 最终都会被执行，无论有异常还是没有异常的时候
#     print("finally")
#     f.close()
#
# def set_age(num):
#     if num <=0 or num >200:
#         raise ValueError(f"值错误：{num}")
#
#     else:
#         print(f"设置的年龄为：{num}")
# set_age(80)

class MyException(Exception):
    def __init__(self,msg):
        print(f"这是一个异常：{msg}")

def set_age(num):
    if num <=0 or num >200:
        raise MyException(f"值错误：{num}")

    else:
        print(f"设置的年龄为：{num}")
set_age(-2)